let config = require("./config");


//获取openid
function GetOpenid(code,callback){
    wx.request({
        url:config.minapp_url + '/AuthCode2Session',
        data:{
            js_code: code,
            pay_mch: config.pay_mch
        },
        method:'GET',
        success: function(e){
            callback&&callback(e);//存在callback才传递数据 否则不传
        }
    })
}

//获取用户信息
function GetUserInfo(openid,callback){
    wx.request({
        url:config.minapp_url + '/GetUserInfo',
        data:{
            openid,
            pay_mch: config.pay_mch
        },
        method:'POST',
        success: function(e){
            callback&&callback(e);//存在callback才传递数据 否则不传
        }
    })
}

//添加用户信息
function AddUserInfo(openid,callback){
    wx.request({
        url:config.minapp_url + '/AddUserInfo',
        data:{
            openid,
            pay_mch: config.pay_mch
        },
        method:'POST',
        success: function(result){
            callback&&callback(result);//存在callback才传递数据 否则不传
        }
    })
}

//获取用户电话号码
function GetUserPhone(openid,session_key,encryptedData,iv,callback){
    wx.request({
        url: config.minapp_url + '/GetPhoneNumberNew',
        data:{
          openid,
          session_key,
          encryptedData:encryptedData,
          iv:iv,
          pay_mch:config.pay_mch
        },
        method:'POST',
        success: function(result){
                callback&&callback(result);//存在callback才传递数据 否则不传
            }
        })
}
//修改电话号电话号码
function EditPhone(openid,tel,callback){
    wx.request({
        url: config.minapp_url + '/UpdatePhoneNumber',
        data: {
          openid: openid,
          phone_num: tel,
          pay_mch: config.pay_mch
        },
        method:'POST',
        success: function(e){
                callback&&callback(e);//存在callback才传递数据 否则不传
            }
        })
}

//获取用户食谱

function GetUserRecipe(phone_num,callback){
    wx.request({
        url: config.minapp_url + '/GetCustomerRecipes',
        data:{
          phone_num
        },
        method:'POST',
        complete:function(e){
            callback&&callback(e);//存在callback才传递数据 否则不传
        }
    })
}

function GetHistory(ustomerId,callback){
    // console.log(ustomerId);
    wx.request({
        url: config.minapp_url + '/GetRecordList',
        data:{
            ustomerId
        },
        method:'GET',
        complete:function(e){
            callback&&callback(e);//存在callback才传递数据 否则不传
        }
    })
}

//获取微信运动步数
function GetStepNum(session_key,encryptedData,iv,callback){
    wx.request({
        url: config.minapp_url + '/GetWeRunData',
        data:{
            session_key,
            encryptedData,
            iv
        },
        method:'POST',
        complete:function(e){
            callback&&callback(e);//存在callback才传递数据 否则不传
        }
    })
}

//获取瘦身工具体重等数据
function GetToolData(openid,callback){
    wx.request({
        url: config.minapp_url + '/GetUserWeight',
        data:{
            openid
        },
        method:'GEt',
        complete:function(e){
            callback&&callback(e);//存在callback才传递数据 否则不传
        }
    })
}
//保存瘦身工具体重等数据
function updateToolData(data,callback){
    wx.request({
        url: config.minapp_url + '/AddUserWeight',
        data:{
            openid:data.openid,
            WaistLine:data.waistlineValue,
            TargetWeight:data.targetValue,
            CurrentWeight:data.nowValue
        },
        method:'POST',
        complete:function(e){
            callback&&callback(e);//存在callback才传递数据 否则不传
        }
    })
}
module.exports={
    GetOpenid,
    GetUserInfo,
    AddUserInfo,
    GetUserPhone,
    EditPhone,
    GetUserRecipe,
    GetHistory,
    GetStepNum,
    GetToolData,
    updateToolData
}   